package com.code.bolg.service.impl;

import com.code.bolg.constant.CookieConstant;
import com.code.bolg.constant.RedisConstant;
import com.code.bolg.service.SpearkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

@Service
public class SpearkServiceImpl implements SpearkService {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public String save(String key, String value) {
        Integer expier = CookieConstant.expier*CookieConstant.expier;
        stringRedisTemplate.opsForValue().set(key, value, expier, TimeUnit.SECONDS);
        return this.find(key);
    }

    @Override
    public Boolean delete(String key) {
        Boolean delete = stringRedisTemplate.delete(key);
        return delete;
    }

    @Override
    public String find(String key) {
        return stringRedisTemplate.opsForValue().get(key);
    }
}
